import tkinter
from tkinter import ttk
class MainWindow():
    def __init__(self):
        self.root = tkinter.Tk()
        self.root.title("login")
        self.root.minsize(200,200)
        self.root.geometry("500x400+100+100")
        self.add_layout()
        

    def add_layout(self):
        """添加登陆视图"""

        frame = ttk.Frame(self.root, padding=5, width = 200, height=200)
        self.user_name = tkinter.StringVar()
        entry_name = ttk.Entry(frame, textvariable=self.user_name)
        entry_name.grid(column=0, row=0)
        self.user_pwd = tkinter.StringVar()
        entry_pwd = ttk.Entry(frame, textvariable=self.user_pwd, show="*")
        entry_pwd.grid(column=0, row=2)
        button_login = ttk.Button(frame, text='login', command=self.login)
        button_login.grid(column=0, row = 4)
        frame.grid(column=0, row=0)
        self.root.rowconfigure(0, weight=1)
        self.root.columnconfigure(0, weight=1)



    def start(self):
        self.root.mainloop()

    def login(self):
        account = self.user_name.get()
        pwd = self.user_pwd.get()
        print(f'账号是{account} 密码是 {pwd}登陆了')

mw = MainWindow()
mw.start()
